package com.klun.aop.SpringProxy;

import com.klun.aop.method.MonitorSession;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * Spring 实现的代理方式
 */
@Aspect
@Component
public class MonitorAdvice {

    /* 定义切入点 */
    @Pointcut("execution (* com.klun.aop.speak.*(..))")
    public void pointcut() {
    }

    /* 对于切入点的开始和结束位置 */
    @Around("pointcut()")
    public void around(ProceedingJoinPoint pjp) throws Throwable {
        MonitorSession.begin(pjp.getSignature().getName());
        pjp.proceed();
        MonitorSession.end();
    }

}
